package com.spider.admin.destroy;

import com.spider.admin.agent.AgentServer;
import com.spider.admin.init.UiServer;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ApplicationDestroy implements DisposableBean, ExitCodeGenerator {

    @Autowired
    UiServer uiServer;

    @Autowired
    AgentServer agentServer;

    @Override
    public void destroy() throws Exception {
        uiServer.stopUiServer();
        log.info("Web容器关闭");
        agentServer.stopAgent();
        log.info("代理服务关闭");
    }

    @Override
    public int getExitCode() {
        return 1;
    }
}
